#include "decoratorquestionnairemodel.h"
#include "sd.h"
#include "readertomodel.h"
#include "writertomodel.h"
#include <QFile>
#include <QStandardItemModel>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QDebug>

DecoratorQuestionnaireModel::DecoratorQuestionnaireModel(QObject *p ) :
	QObject(p), m(new QStandardItemModel(0, 2,this)), q(-1),
	r(new ReaderToModel(m, new QXmlStreamReader(), this)),
	w(new WriterFromModel(m, new QXmlStreamWriter(), this)){
	m->setHeaderData(0, Qt::Horizontal, trUtf8("Текст"));
	m->setHeaderData(1, Qt::Horizontal, trUtf8("Тип"));
}


void DecoratorQuestionnaireModel::selectQuestion (int question){
	q = question;
}

void DecoratorQuestionnaireModel::save (const QString & fn){
	w->streamWriter()->setDevice(new QFile(fn, this));
	w->write();
}


QAbstractItemModel * DecoratorQuestionnaireModel::model() const{
	return m;
}

void DecoratorQuestionnaireModel::open(const QString & fn){
	r->streamReader()->setDevice(new QFile(fn, this));
	r->read();
}

int DecoratorQuestionnaireModel::question(){
	return q;
}
